//
//  CYShopCartCell.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/8/1.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYShopCartCell.h"
@interface CYShopCartCell()
@property (nonatomic, strong) CYLabel *bettingWayLBL;//投注方式
@property (nonatomic, strong) CYLabel *detailLBL;//投注说明
@property (nonatomic, strong) CYLabel *moneyLBL;//投注数目，金额
@property (nonatomic, strong) CYView *topLine;//cell上部划线
@property (nonatomic, strong) CYLabel *numberLBL;//号码框

@end
@implementation CYShopCartCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.topLine.hidden = NO;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return self;
}

- (CYLabel *)numberLBL{
    if (!_numberLBL) {
        _numberLBL = [[CYLabel alloc]initWithText:nil size:AL(PT(26)) textcolor:ORANGE_COLOR];
        _numberLBL.numberOfLines = 0;
        [self addSubview:_numberLBL];
        [_numberLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(AL(PT(20)));
            make.right.equalTo(self).with.offset(-AL(PT(20)));
            make.top.equalTo(self).with.offset( AL(PT(10)));
        }];
    }
    return _numberLBL;
}

- (CYLabel *)bettingWayLBL{
    if (!_bettingWayLBL) {
        _bettingWayLBL = [[CYLabel alloc]initWithText:_bettingWay size:AL(PT(26)) textcolor:ColorHex(0x333333)];
        [self addSubview:_bettingWayLBL];
        
        [_bettingWayLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(AL(PT(20)));
            make.top.equalTo(_numberLBL.mas_bottom).with.offset( AL(PT(10)));
            make.size.mas_equalTo(_bettingWayLBL.bounds.size);
        }];
    }
    return _bettingWayLBL;
}

- (CYLabel *)detailLBL{
    if (!_detailLBL) {
        _detailLBL = [[CYLabel alloc]initWithText:[NSString stringWithFormat:@"(%@)", _detail] size:AL(PT(26)) textcolor:ColorHex(0x888888)];
        [self addSubview:_detailLBL];
        
        [_detailLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_bettingWayLBL.mas_right).with.offset(AL(PT(10)));
            make.centerY.equalTo(_bettingWayLBL);
            make.size.mas_equalTo(_detailLBL.bounds.size);
        }];
    }
    return _detailLBL;
}

- (CYLabel *)moneyLBL{
    if (!_moneyLBL) {
        _moneyLBL = [[CYLabel alloc]initWithText:[NSString stringWithFormat:@"%d注%d倍%d元", _bettingNum, _bettingTime, _bettingMoney] size:AL(PT(26)) textcolor:ColorHex(0x333333)];
        [self addSubview:_moneyLBL];
        
        [_moneyLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_detailLBL.mas_right).with.offset(AL(PT(20)));
            make.centerY.equalTo(_detailLBL);
            make.size.mas_equalTo(_moneyLBL.bounds.size);
        }];
    }
    return _moneyLBL;
}

- (CYView *)topLine{
    if (!_topLine) {
        _topLine = [[CYView alloc]initWithColor:ColorHex(0x888888)];
        [self addSubview:_topLine];
        
        [_topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).with.offset(0);
            make.left.equalTo(self).with.offset(0);
            make.right.equalTo(self).with.offset(0);
            make.height.mas_equalTo(0.5);
        }];
    }
    return _topLine;
}

- (CYImageView *)bottomIMG{
    if (!_bottomIMG) {
        _bottomIMG = [[CYImageView alloc]initWithImageName:@"bagbow" size:CGSizeMake(SCREEN_WIDTH - AL(PT(42)) * 2 - AL(8), AL(8)) isRadius:NO];
        [self addSubview:_bottomIMG];
        
        [_bottomIMG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_bottom).with.offset(0);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(_bottomIMG.bounds.size);
        }];
    }
    return _bottomIMG;
}

- (void)setNumber:(NSString *)number{
    if (_number != number)
        _number = number;
    self.numberLBL.text = number;
    self.numberLBL.bounds = CGRectMake(0.0, 0.0, _width - AL(PT(40)), self.numberLBL.bounds.size.height);
    [_numberLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo([_numberLBL autoSizeWithWidth:(_width - AL(PT(40)))].height);
        make.width.mas_equalTo(_numberLBL.bounds.size.width);
    }];
    
}

- (void)setBettingWay:(NSString *)bettingWay{
    if (_bettingWay != bettingWay)
        _bettingWay = bettingWay;
    self.bettingWayLBL.hidden = NO;
}

- (void)setDetail:(NSString *)detail{
    if (_detail != detail)
        _detail = detail;
    self.detailLBL.hidden = NO;
    
}

- (void)setBettingNum:(int)bettingNum{
    if (_bettingNum != bettingNum)
        _bettingNum = bettingNum;
    self.bettingMoney = _bettingNum * _bettingTime * 2;
}

- (void)setBettingMoney:(int)bettingMoney{
    if (_bettingMoney != bettingMoney)
        _bettingMoney = bettingMoney;
        self.moneyLBL.text = [NSString stringWithFormat:@"%d注%d倍%d元", _bettingNum, _bettingTime, _bettingMoney];
        [_moneyLBL mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(_moneyLBL.bounds.size);
        }];
}

- (void)setBettingTime:(int)bettingTime{
    if (_bettingTime != bettingTime)
        _bettingTime = bettingTime;
    self.bettingMoney =_bettingNum * _bettingTime * 2;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
